<%--
  Created by IntelliJ IDEA.
  User: 陈杰
  Date: 2020/8/10
  Time: 11:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    /*basePath===http://localhost:8080/TestServlet04/*/
%>
<html>
<head>
    <title>学生各科成绩表</title>
    <script type="text/javascript" src="<%=basePath%>static/js/jquery-1.11.3.min.js"></script>

    <link rel="stylesheet" href="<%=basePath%>static/css/bootstrap-theme.css">
    <%--    <link rel="stylesheet" href="<%=basePath%>static/css/pintuer.css">--%>


    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">

    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="<%=basePath%>static/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="<%=basePath%>static/js/jqPaginator.js"></script>
</head>
<body >


</center>
</div>
<table class="table table-hover" border="1" width="50%">
    <tr>

        <td>学生编号</td>
        <td>学生id</td>
        <td>学生姓名</td>
        <td>课程名称</td>
        <td>成绩</td>
<%--        <td colspan="1">操作</td>--%>

    </tr>
    <tbody id="tb">
    </tbody>
</table>
</body>

<script>
    //文档加载后要执行的函数
    $(document).ready(function(){
        loadData();
    });

    function loadData() {
        var sno = '<%=session.getAttribute("userId")%>';
        //jquery的ajax请求方法
        $.ajax({
            url: "<%=basePath%>student/queryResult",
            async: false,//同步请求（默认）
            type: "POST",
            dataType: "json",
            data: {"sno": sno},
            success: function (data) {
                console.log(data);
                $("#tb").html("");
                if(data.length>0){
                    //使用jquery形式遍历
                    $.each(data, function (n, val) {
                        var str = "";
                        str += "<tr>" +
                            "<td>" +  data[n].sno + "</td>" +
                            "<td>" +  data[n].sid + "</td>" +
                            "<td>" +  data[n].sname + "</td>" +
                            "<td>" +  data[n].coursename + "</td>" +
                            "<td>" +  data[n].record + "</td>" +
                            "</tr>";
                        $("#tb").append(str);
                    });
                } else {
                    $("#tb").append("<tr><td colspan=8 align=\"center\">暂时没有数据哦，快去添加一条吧</td></tr>");
                }
            },
            error: function () {
                alert("服务器出错！");
            }
        });
    }
</script>
</html>
